﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_Bill_Staff : System.Web.UI.Page
{
    private UserAccountBlo _UABlo = new UserAccountBlo();
    private MobileBlo _MobileBlo = new MobileBlo();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadSearchByUserAccount("","");
        }
    }
    private void LoadSearchByUserAccount(string _searchColumn,string _searchString)
    {
        gdvSearchByUserAccount.DataSource = _UABlo.SelectUserAccountBy(_searchColumn, _searchString);
        gdvSearchByUserAccount.DataBind();
    }
    private void LoadSearchByUserAccount()
    {
        string _searchColumn = ddlUserAccount.SelectedValue.ToString();
        string _searchString;
        _searchString = txtSearchUserAccount.Text.ToString();
        gdvSearchByUserAccount.DataSource = _UABlo.SelectUserAccountBy(_searchColumn, _searchString);
        gdvSearchByUserAccount.DataBind();
    }
    protected void gdvSearchByUserAccount_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        
        int id_UA = int.Parse(gdvSearchByUserAccount.DataKeys[e.RowIndex].Value.ToString());        
        gdvMobileNumber.DataSource = this.SelectMobileByID_UA(id_UA);
        gdvMobileNumber.DataBind();
    }
    private List<MobileDto> SelectMobileByID_UA(int id_UA)
    {
        return _MobileBlo.SelectMobileByID_UA(id_UA);
    }

    protected void gdvSearchByUserAccount_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {        
        gdvSearchByUserAccount.PageIndex = e.NewPageIndex;
        LoadSearchByUserAccount();        
    }
    protected void btnShowAllUserAccount_Click(object sender, EventArgs e)
    {
        LoadSearchByUserAccount("", "");
        txtSearchUserAccount.Text = "";
    }
    protected void btnSearchUserAccount_Click(object sender, EventArgs e)
    {
        LoadSearchByUserAccount();
    }
    protected void gdvMobileNumber_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        int id_MN = int.Parse(gdvMobileNumber.DataKeys[e.RowIndex].Value.ToString());
        Response.Redirect("Bill.aspx");     //Truyen ID_MN vao session de goi ra bill.aspx        
    }
    protected void btnMobileNumber_Click(object sender, EventArgs e)
    {
        int id_MN;
        string number=txtMobileNumber.Text;
        id_MN = _MobileBlo.SelectMobileByNumber(number).Id_MN;
        //Response.Redirect("Bill.aspx");     //Truyen ID_MN vao session de goi ra bill.aspx   
        lblStatus.Visible = true;
        lblStatus.Text = id_MN.ToString();
    }
}